#include <iostream>
using namespace std;

int n, a, b; //获取输入
int x, y;    //获取答案

int exgcd(int a, int b, int &x, int &y) //返回的是a与b的最大公因数，x与y满足ax+by=gcd(a,b)
{
    if (!b) //如果b为0，此时a为gcd(a,b)
    {
        x = 1, y = 0;
        return a;
    }
    int x0, y0;
    int d = exgcd(b, a % b, x0, y0);
    x = y0;
    y = x0 - a / b * y0;
    return d;
}

int main()
{
    cin >> n;
    while (n--)
    {
        cin >> a >> b;
        exgcd(a, b, x, y);
        printf("%d %d\n", x, y);
    }
    return 0;
}